<template>

    <div>
      <!--增加-->
      <!--<el-dialog title="新增视频" :visible.sync="dialogFormVisible" >-->

        <el-form :model="videoadd">
          <el-form-item label="视频的描述" label-width="100px">
            <el-input v-model="videoadd.videoInfo" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item label="类型">
            <el-select v-model="videoadd.videoTypeid" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.typeId"
                :label="item.typeName"
                :value="item.typeId">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="选择他人是否可见">
            <el-select v-model="videoadd.videoIspublic" placeholder="请选择">
              <el-option
                v-for="items in optionss"
                :key="items.value"
                :label="items.label"
                :value="items.value">
              </el-option>
            </el-select>
          </el-form-item>
          <!--enctype="multipart/form-data"-->
          <!--:show-file-list="true"-->
          <el-upload
            class="upload-demo"
            drag
            enctype="multipart/form-data"
            action="api/videos/upload"
            :on-success="handleAvatarSuccess"
            multiple>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip"></div>
          </el-upload>

        </el-form>


        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="oninsert">确 定</el-button>
        </div>

      <!--</el-dialog>-->

    </div>
</template>

<script>

  import axios from 'axios'
   axios.defaults.withCredentials=true

    export default {
      data() {
        return {
          videoadd:{},
          formLabelWidth:100,
          options: [],
          dialogFormVisible:true,
          optionss: [{
            value: 1,
            label: '所有人可见'
          }, {
            value: 0,
            label: '仅自己可见'
          }],
          items:{
            value:0
          }
        }
      },

      methods: {
        handleAvatarSuccess(res, file){
          alert(res);
          this.videoadd.videoUrl=res;
          this.$message({
            message:"上传成功！",
            type: 'success'
          });
        },
        findAll:function () {
          axios.get("http://localhost/kd-videotype/videoType/findtypes").then(res=>{
            //地址传参
            //debugger;
            //axios.post("http://localhost/shop-shop/shop/findAll"+this.params.page+"/"+this.params.size).then(res=>{
            console.log(res.data.code)
            if (res.data.code==200){
              this.options = res.data.data;
              // alert (res.data);
               //alert (res.data.data);
              console.log(res.data);
            } else{
              alert(res.data.code);
            }
          })
        },
        oninsert(){
          //请求后台进行修改数据
          //关闭模态窗口
          this.$confirm('确定要添加吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            axios.post("http://localhost/kd-video/videos/saveAndFlush",this.videoadd).then(res=>{
              //alert("64");
              if(res.data.code==200){
                this.$message({
                  type: 'success',
                  message: '提交成功!'
                });

              }else {
                this.$message({
                  type: 'warning',
                  message: '提交失败!'
                });
              }
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消提交'
            });
          });
        },
      },
      mounted(){
        this.findAll();
      }
      }

</script>

